//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    if (this.data.canIUse) {
      console.log('可以open-type.getUserInfo')
    } else {
      wx.getUserInfo({
        success: (res) => {
          wx.setStorageSync({
            key: 'userInfo',
            data: res.userInfo,
          })
        }
      })    
    }
  },
  getUserInfo: function(e) {
    if (e.detail.userInfo) {
      wx.setStorageSync('userInfo', e.detail.userInfo)
      wx.switchTab({
        url: '/pages/home/home',
      })
    } else {
      app.toast('请点击允许按钮')
    }
  }
})
